<template>
	<view class="mainpadding">
		<!-- 书籍 -->
		<view class="shu mainpadding radius ffffff flexleft">
			<view class="tupian radius">
				<image class="radius" :src="detailmsg.goodsList[0].thumb_image" mode=""></image>
			</view>
			<view class="rt">
				<view class="mingzi">{{detailmsg.goodsList[0].name}}</view>
				<view class="qiang" v-show="detailmsg.goodsList[0].sku_title">{{detailmsg.goodsList[0].sku_title}}</view>
				<view class="qiang" v-show="!detailmsg.goodsList[0].sku_title"></view>
				<view class="qianshu">￥{{detailmsg.goodsList[0].goods_price}}</view>
			</view>
		</view>
	
	     <!-- 个人信息 -->
		 <view class="gerenxix shu radius margin_top">
		 	<view class="peisong mainpadding">配送方式：快递免邮</view>
			<view class="flexbetween mainpadding">
				<view class="flexleft">
					<view class="peisong">备注信息：</view>
					<input type="text" placeholder="请输入备注信息" v-model="beizhu">
				</view>
				<view class="icon">
					<image src="../../static/image/system/righticon.png" mode=""></image>
				</view>
			</view>
			<view class="peisong mainpadding">购买数量：{{detailmsg.total}}件</view>
			<view class="peisong mainpadding">总金额：
			<text class="zongqianshu">{{detailmsg.pay_price}}元</text>
			</view>
			<!-- 输入框 -->
			<view class="mainpadding2">
				<view class="input">
					<input type="text" placeholder="请填写收货人姓名" v-model="name">
				</view>
				<view class="input margin_top">
					<input type="text" placeholder="请填写手机号码" v-model="phonenum">
				</view>
				<view class="inpbox input flexbetween margin_top">
					<uni-data-picker :localdata="items" placeholder="请选择住址" popup-title="请选择地区" v-model="area"
						@change="bindPickerChange">
						<view class="word12" v-if="!area.length">请选择收货地址</view>
						<view class="word13" v-else>{{ area[0] }}/{{ area[1] }}/{{ area[2] }}</view>
					</uni-data-picker>
					<view class="maptub">
						<image src="../../static/image/system/map.png" mode=""></image>
					</view>
				</view>
			<textarea class="textarea radius mainpadding margin_top" maxlength="80" cols="30" rows="10" placeholder="请输入详细地址.." v-model="xiangxi"></textarea>
			</view>
		 </view>
		 <!-- 按钮 -->
		 <view class="tuiku mainpadding margin_top" @click="submit">提交订单</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	import citys from "../../static/city/city.js"
	export default {
		data() {
			return {
				detailmsg:{},
				beizhu:"",
				name:"",
				phonenum:"",
				xiangxi:"",
				// 省市区选择
				area: [], //收获地址
				sh_name: "", //收货人
				sh_mobile: "", //收货人
				xx_address: "", //详细地址
				address: {
					province: "",
					city: "",
					county: ""
				},
				items: citys.data,
				buymsg: {},
				wxpay:{}
			}
		},
		onLoad(options) {
			this.detailmsg = JSON.parse(decodeURIComponent(options.msg))
			console.log(this.detailmsg)
		},
		methods: {
			// 购买书籍
			submit(){
				let _this = this
				let address =  _this.area[0]+_this.area[1]+_this.area[2]
				if(_this.name==""){
					httpRequest.toast("请输入收货人名称")
					return false
				}
				if(_this.phonenum==""){
					httpRequest.toast("请输入收货人电话")
					return false
				}
				if(_this.address==""){
					httpRequest.toast("请选择收货人地址")
					return false
				}
				if(_this.xiangxi==""){
					httpRequest.toast("请填写详细地址")
					return false
				}
				httpRequest.request('/api/order/create_order', 'POST', {
					type: "detail",
					ids:_this.detailmsg.goodsList[0].id,
					goods_sku_id: _this.detailmsg.goodsList[0].goods_sku_id,
					goods_num: _this.detailmsg.total,
					address:{
						name:_this.name,
						mobile:_this.phonenum,
						address:address,
						address_detail:_this.xiangxi
					},
					remarks:_this.beizhu
				}, false, false, true).then(res => {
					this.buymsg = res.data
					this.pay()
				})
			},
			// 课程支付接口
			pay() {
				httpRequest.request('/api/pay/pay', 'POST', {
					type: "goods",
					platform: "wxmini",
					order_id: this.buymsg.id,
					pay_type: 1
				}).then(resp => {
					this.wxpay = resp.data
					this.callPayMent()
				})
			},
			// 调用微信支付接口
			callPayMent() {
				let _this = this;
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: _this.wxpay.timeStamp,
					nonceStr: _this.wxpay.nonceStr,
					package: _this.wxpay.package,
					signType: _this.wxpay.signType,
					paySign: _this.wxpay.paySign,
					success: function(res) {
						// 支付成功
						uni.navigateBack({
							delta:1
						})
					},
					fail: function(err) {
						// 支付失败
						// _this.paycatchresult = true
					}
				});
			},
			// 地区选择
			bindPickerChange(val) {
				let area = val.detail.value
				this.area = [area[0].text, area[1].text, area[2].text];
				this.address.province = area[0].value;
				this.address.city = area[1].value;
				this.address.county = area[2].value;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textarea{
		background: #F6F6F6;
		width: 100%;
		box-sizing: border-box;
	}
	.maptub{
		width: 28rpx;
		height: 30rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.inpbox{
		background: #F6F6F6;
		border-radius: 50rpx;
		padding-right: 30rpx;
	}
	.inputs{
		width: 80%;
		background: #F6F6F6;
		border-radius: 50rpx;
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		height: 100rpx;
		color: #999999;
		padding:0 30rpx ;
	}
	.input{
		width: 100%;
		background: #F6F6F6;
		border-radius: 50rpx;
		font-size: 30rpx;
		box-sizing: border-box;
		padding:30rpx;
	}
	.zongqianshu{
		color:#FF3939 ;
	}
	.peisong{
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}
	.icon {
		margin: 0 0 14rpx 0;
		width: 14rpx;
		height: 24rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
	.peisong{
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}
	.shu{
		box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(51,51,51,0.1000);
	}
	.qianshu{
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #FF3939;
	}
	.mingzi {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #333333;
	}
    .qiang{
		margin: 15rpx 0 37rpx;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333
	}
	.tupian {
		width: 206rpx;
		height: 189rpx;
        margin-right: 30rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	// 地址选择
	.word12{
		color: #808080;
		width:550rpx;
	}
	.word13{
		color: #333333;
		width:550rpx;
	}
</style>
